package com.njust.diary.Controlller;
import cn.hutool.core.util.StrUtil;
import com.njust.diary.po.Health;
import com.njust.diary.po.Note;
import com.njust.diary.po.NoteType;
import com.njust.diary.po.User;
import com.njust.diary.service.HealthService;
import com.njust.diary.service.NoteService;
import com.njust.diary.service.NoteTypeService;
import com.njust.diary.service.UserService;
import com.njust.diary.vo.Result;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
@WebServlet("/question")

public class QuestionServlet extends  HttpServlet{
    private HealthService healthService =new HealthService();

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String actionName=req.getParameter("actionName");
        if("view".equals(actionName)){

            questionView(req,resp);

        }else if("submit".equals(actionName)){

            healthView(req,resp);
        }


    }

    private void healthView(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{

        Integer age = Integer.valueOf(req.getParameter("age"));
        Integer weight = Integer.valueOf(req.getParameter("weight"));
        Integer height = Integer.valueOf(req.getParameter("height"));
        Integer gender=Integer.valueOf(req.getParameter("sex"));
        Integer xue1=Integer.valueOf(req.getParameter("xue1"));
        Integer xue2=Integer.valueOf(req.getParameter("xue2"));
        Integer xue3=Integer.valueOf(req.getParameter("xue3"));
        Integer xin1=Integer.valueOf(req.getParameter("xin1"));
        Integer xin2=Integer.valueOf(req.getParameter("xin2"));
        Integer xin3=Integer.valueOf(req.getParameter("xin3"));
        Integer yi1=Integer.valueOf(req.getParameter("yi1"));
        Integer yi2=Integer.valueOf(req.getParameter("yi2"));
        Integer yi3=Integer.valueOf(req.getParameter("yi3"));
        Integer jiao1=Integer.valueOf(req.getParameter("jiao1"));
        Integer jiao2=Integer.valueOf(req.getParameter("jiao2"));
        User user =(User) req.getSession().getAttribute("user");

        Result<Integer> result =healthService.updateHealth(user.getUserId(),age,gender,weight,height,req,xue1,xue2,xue3,xin1,xin2,xin3,yi1,yi2,yi3,jiao1,jiao2);
        req.setAttribute("result",result);


        req.getRequestDispatcher("user?actionName=userCenter").forward(req,resp);
    }

    private void questionView(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setAttribute("menupage","question");

        req.setAttribute("changePage","question/question.jsp");
        req.getRequestDispatcher("index.jsp").forward(req,resp);

    }


}
